var express = require("express");
var router = express.Router();
const {
  getNavsAll,
  addNav,
  delNav,
  changeNav,
  getOne,
} = require("../api/navs");

//获取所有商品大类的数据
router.get("/", async function (req, res, next) {
  const data = await getNavsAll();
  res.send(data);
});
//新增商品大类
router.post("/", async function (req, res, next) {
  const { name } = req.body;
  const data = await addNav({
    name,
  });
  res.send(data);
});
//删除商品大类
router.delete("/del", async function (req, res, next) {
  const { _id } = req.body;
  const data = await delNav(_id);
  res.send(data);
});
//获取某一条商品大类的数据
router.get("/:_id", async function (req, res, next) {
  const { _id } = req.query;
  const data = await getOne(_id);
  res.send(data);
});
//修改商品大类数据
router.put("/change", async function (req, res, next) {
  const newData = req.body;
  const data = await changeNav(newData);
  res.send(data);
});
module.exports = router;
